package com.fan.commons.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author fan
 * @date 2021/1/25
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class JsonResult {

	/**
	 * 状态码 0 正常，1 不正常
	 */
	private Integer code;

	/**
	 * 提示信息
	 */
	private String msg;

	/**
	 * 返回的数据
	 */
	private Object data;

	public static JsonResult success(Object data) {
		return new JsonResult(0, "success", data);
	}

	public static JsonResult success(String msg, Object data) {
		return new JsonResult(0, msg, data);
	}


	public static JsonResult failure() {
		return new JsonResult(1, "failuer", null);
	}

	public static JsonResult failure(String msg) {
		return new JsonResult(1, msg, null);
	}

	public static JsonResult failure(String msg, Object data) {
		return new JsonResult(1, msg, data);
	}
}
